<template>
    <div style="background-color: #f8f8f9;">
        <div class="container">
            <!-- 顶部搜索 -->
            <div class="home_main">
                <div class="search">
                    <input type="text" placeholder="梵蒂冈">
                </div>
                <div class="srach" @click="srach">搜索</div>
            </div>

            <div v-if="hgc">
                <div class="recommend">
                    <div class="commend">
                        <p>大家都在搜</p>
                    </div>
                    <div class="block_list clearfix">
                        <div class="item clearfix">
                            <p>梵蒂冈</p>
                            <span>永恒之城</span>

                        </div>
                        <div class="item">
                            <p>《新神榜：杨戬》</p>
                            <!---->
                        </div>
                    </div>
                </div>

                <div class="tab">
                    <p :class="num == 0 ? 'active' : ''" @click="num = 0">商品热销榜</p>
                    <p :class="num == 1 ? 'active' : ''" @click="num = 1">众筹排行榜</p>

                </div>

                <div class="lists" v-if="num == 0">
                    <ul>
                        <li v-for="(item, index) in list" :key="index">
                            <span>{{ item.id }}</span>
                            <div class="text">
                                <p>{{ item.title }}</p>
                                <p>¥{{ item.price }}</p>
                            </div>
                            <div class="imgs"><img src="../assets/img/search.jpg" alt=""></div>
                        </li>
                    </ul>
                </div>

                <div class="lists" v-if="num == 1">
                    <ul>
                        <li v-for="(item, index) in list" :key="index">
                            <span>{{ item.id + 8 }}</span>
                            <div class="text">
                                <p>1{{ item.title }}</p>
                                <p>¥{{ item.price }}</p>
                            </div>
                            <div class="imgs"><img src="../assets/img/search.jpg" alt=""></div>
                        </li>
                    </ul>
                </div>
            </div>
            <div v-if="!hgc">
                <div class="shopList">
                    <router-link to="/CommodityView" tag="div" class="left" v-for="(item, index) in lists.data.lists"
                        :key="index">
                        <div class="img"><img :src="item.imgs" alt=""></div>
                        <div class="text">
                            {{item.title}}
                        </div>
                        <div class="price">￥10 <s>￥10</s></div>
                        <div class="pro">10人想要</div>
                    </router-link>
                </div>
            </div>



        </div>

    </div>
</template>

<script>
import { getName } from "../assets/api/home.js"
export default {
    data() {
        return {
            num: 0,
            list: [
                {
                    id: 1,
                    title: '《某某》原著向衍生周边-第二期 徽章',
                    price: '23.00',
                },
                {
                    id: 2,
                    title: '核反应堆充电宝透明机甲20000毫安超大容量小巧便携',
                    price: '97.00',
                },
                {
                    id: 3,
                    title: '《《某某》原著向衍生周边-第二期 签名板（色纸）',
                    price: '23.00',
                },
                {
                    id: 4,
                    title: '【限时特价】《掌中艺术家 梵高笔下的印象派》',
                    price: '23.00',
                },
                {
                    id: 5,
                    title: '《某某》原著向衍生周边-第二期 徽章',
                    price: '23.00',
                },
                {
                    id: 6,
                    title: '核反应堆充电宝透明机甲20000毫安超大容量小巧便携',
                    price: '97.00',
                },
                {
                    id: 7,
                    title: '《《某某》原著向衍生周边-第二期 签名板（色纸）',
                    price: '23.00',
                },
                {
                    id: 8,
                    title: '【限时特价】《掌中艺术家 梵高笔下的印象派》',
                    price: '23.00',
                },


            ],
            lists: null,
            hgc: true,
        };
    },
    methods: {
        getNamefun() {
            getName().then((data) => {
                this.lists = data;
                console.log(this.lists.data.lists);
            })
        },
        srach() {
            console.log(this.lists.data.lists);

        }
    },
    created() {
        this.getNamefun()
    },

}
</script>

<style lang="scss">
.home_main {
    background-color: #fff;
    height: 42px;
    padding: 10px 13px;
    display: flex;
    justify-items: center;

    .icon {
        width: 14%;
        text-align: center;

        img {
            width: 27px;
            height: 27px;
            margin: 6px auto 0 auto;
        }
    }

    .search {
        flex: 1;
        height: 32px;
        line-height: 32px;
        border: 1px solid #e5e5e5;
        font-size: 16px;
        margin-top: 4px;
        color: #b7b7b7;
        padding-left: 31px;
        background: #fff url("../assets/img/下载.png") 6px 6px no-repeat;
        background-size: 20px;

        input {
            width: 100%;
            border: none;
        }
    }

    .srach {
        float: left;
        width: 68px;
        height: 42px;
        line-height: 42px;
        cursor: pointer;
        color: #EF8833;
        text-align: center;
        font-size: 16px;
    }
}

.recommend {
    margin-top: 10px;
    padding: 0px 13px;
    background-color: #fff;

    .commend {
        position: relative;
        height: 45px;
        line-height: 45px;

        p {
            width: 80px;
            font-size: 14px;
            color: #7a8087;
            background-color: #fff;
            position: absolute;
            z-index: 100;
        }
    }

    .commend::after {
        content: '';
        height: 1px;
        width: 100%;
        background: #DEE0E1;
        position: absolute;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        z-index: 1;
    }

    .block_list {
        height: 46px;

        .item {
            height: 27px;
            width: auto;
            float: left;
            padding: 0 14px;
            box-sizing: border-box;
            -webkit-box-sizing: border-box;
            margin: 1px 10px 0 0;
            font-size: 12px;
            line-height: 27px;
            text-align: center;
            cursor: pointer;
            white-space: nowrap;
            overflow: hidden;
            border: 1px solid #BCBFC3;
            display: flex;

            span {
                float: left;
                height: 12px;
                border-radius: 2px;
                color: #fff;
                font-size: 12px;
                padding: 0 2px;
                text-align: center;
                line-height: 12px;
                font-weight: 700;
                margin-left: 6px;
                margin-top: 8px;
                background: #00D6A6;
            }
        }
    }

}

.tab {
    padding: 0 13px;
    height: 46px;
    line-height: 46px;
    background-color: #fff;
    border-bottom: 1px solid #dee0e1;

    p {
        display: inline-block;
        font-size: 16px;
        line-height: 14px;
        height: 30px;
        font-weight: 700;
        color: #BCBFC3;
        margin-right: 30px;
        position: relative;

        &.active {
            color: #000;
        }

        &.active::after {
            content: "";
            position: absolute;
            width: 17px;
            height: 3px;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            background: #1F2C38;
        }
    }
}

.lists {
    background-color: #fff;

    ul {
        li {
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: space-between;

            span {
                padding: 10px 8px;
                margin: 0 12px;
                width: 25px;
                // background: url(../assets/img/rask_1.png) no-repeat center center;
                // background-size: 100%;
            }

            .text {
                padding: 3px;
                width: 260px;

                p:first-child {
                    font-size: 18px;
                    line-height: 18px;
                    font-weight: 700;
                    color: #1F2C38;
                    width: 100%;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                }

                p:last-child {
                    padding-top: 9px;
                    font-size: 14px;
                    line-height: 14px;
                    color: #EC6230;
                    font-weight: 400;
                }

            }

            .imgs {
                width: 50px;
                height: 50px;
                margin-right: 13px;
            }
        }
    }
}

.shopList {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;

    .left {
        width: 177px;
        height: 309px;
        background-color: #f2f2f2;
    }

    .text {
        font-size: 14px;
        margin: 0 0 33px;
        color: #1a1a1a;
        height: 36px;
        line-height: 20px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .price {
        font-size: 18px;
        color: #ff3d20;
        font-weight: bolder;

        s {
            font-size: 12px;
            color: #b1b1b1;
            font-weight: 400;

        }
    }

    .pro {
        margin-top: 14px;
        font-size: 12px;
        font-weight: 400;
        color: #1a1a1a;
    }
}
</style>